#include "process.h"


void process_1()
{
    int rate = 0;
    char str[MAX_TIME];
    char state[] = { '|', '/', '-', '\\' };

    memset(str, '\0', MAX_TIME);

    while (rate < MAX_TIME)
    {
        printf("[%-100s][%d\%][%c]\r", str, rate, state[rate % 4]);
        fflush(stdout);
        usleep(SLEEPTIME);

        str[rate++] = STYLE;
    }
    printf("\n");

    return;
}


void process_2(int rate)
{ 
    static char str[MAX_TIME] = { 0  };
    static int cnt = 0;
    cnt++;
    cnt %= 4;
    char state[] = { '|', '/', '-', '\\' };


    if (0 <= rate && rate <= MAX_TIME)
    {
        printf("[%-100s][%d\%][%c]\r", str, rate, state[cnt]);
        fflush(stdout);

        str[rate] = STYLE;
    }

}


//美化版本
void process_3(double rate)
{ 
    static char str[MAX_TIME] = { 0  };
    static int cnt = 0;
    cnt++;
    cnt %= 4;
    char state[] = { '|', '/', '-', '\\' };


    if (0 <= rate && rate <= MAX_TIME)
    {
        if (rate > 100) rate = 100;

        printf("[%-100s][%.2lf\%][%c]\r", str, rate, state[cnt]);
        fflush(stdout);

        if (rate < MAX_TIME)
        {
            str[(int)rate] = STYLE;
            str[(int)rate + 1] = STYLE_HENDER;

        }
        else
        {
            str[(int)rate] = STYLE;
        }
    }   
}


